-- Rogue Rage
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Darren Grey
-- http://gruesomegames.com

require "engine.class"
local ActorAI = require "engine.interface.ActorAI"
local Faction = require "engine.Faction"
local Map = require "engine.Map"
local Astar = require"engine.Astar"
local DirectPath = require"engine.DirectPath"
local Talents = require "engine.interface.ActorTalents"
local Particles = require "engine.Particles"
require "mod.class.Actor"

module(..., package.seeall, class.inherit(mod.class.Actor, engine.interface.ActorAI))

function _M:init(t, no_default)
	t.s_count_max = t.s_count_max or 0
	t.s_count = t.s_count or 0
	t.ranged = t.ranged or false
	t.sight = t.sight or 8
	
	t.speed = t.speed or 0
		
	mod.class.Actor.init(self, t, no_default)
	ActorAI.init(self, t)
	
	if self.ranged then	self.ai = "flee_dmap" end
	
end

function _M:tooltip()
   
   if self.invis then return false else
   
   local enemy_damage = self.power - game.player.armour
   if enemy_damage < 1 then enemy_damage = 1 end
   
   local enemy_aim = 50 + 10*(self.aim - game.player.dodge)
   if enemy_aim < 10 then enemy_aim = 10 end
   if enemy_aim > 100 then enemy_aim = 100 end
   
   local player_damage = game.player.power - self.armour
   if player_damage < 1 then player_damage = 1 end
   
   local player_aim = 50 + 10*(game.player.aim - self.dodge)
   if player_aim < 10 then player_aim = 10 end
   if player_aim > 100 then player_aim = 100 end
   
   return ([[%s %s
#SLATE#%s#LAST#
Life: #KHAKI#%d / %d#LAST#
Does %d damage with %d%% chance to hit
You do %d damage with %d%% chance to hit
 
]]):format(
	self:getDisplayString(), self.name,
	self.desc,
	self.life, self.max_life,
	enemy_damage, enemy_aim,
	player_damage, player_aim
    
	)
	end
end

function _M:act()
	-- Do basic actor stuff
	if not mod.class.Actor.act(self) then return end

	self:computeFOV(10)

	if self.ranged and self:isNear(game.player.x, game.player.y, self.ranged_dist) then
		self.ai = "flee_dmap"
	else
		self.ai = "dumb_talented_simple"
		if self.annoying then self.ranged = false end
	end
	
	
	
		
	-- Let the AI think
	-- If AI did nothing, use energy anyway
	if not self.energy.used then
		self:doAI()
		if not self.energy.used then self:useEnergy() end
	end
end


--- Called by ActorLife interface
-- We use it to pass aggression values to the AIs
function _M:onTakeHit(value, src)
	if not self.ai_target.actor and src.targetable then
		self.ai_target.actor = src
	end

	return mod.class.Actor.onTakeHit(self, value, src)
end


